package com.asiainfo.dacp.datastash.orm.po.state;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.Table;
import javax.persistence.Transient;

import com.asiainfo.dacp.jpa.annotation.ColumnPosition;
import com.asiainfo.dacp.util.DateHelper;

import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@Entity
@Table(name = "dacp_datastash_unit_task_state")
@NoArgsConstructor
public class DataStashUnitTaskStateLogPo {

	@Id
	@Column(name = "task_proc_id", length = 32)
	private String taskProcId;

	@Column(name = "unit_proc_id", length = 32)
	@ColumnPosition(1)
	private String unitProcId;

	@Column(name = "unit_code", length = 16)
	@ColumnPosition(2)
	private String unitCode;

	@Column(name = "batch_no", length = 16)
	@ColumnPosition(3)
	private String batchNo;

	@Column(name = "task_type", length = 8)
	@ColumnPosition(4)
	private String taskType;

	@Lob
	@Column(name = "task_steps")
	@ColumnPosition(5)
	private String taskSteps;

	@Column(name = "pre_task_pid", length = 128)
	@ColumnPosition(6)
	private String preTaskProcIds;

	@Column(name = "next_task_pid", length = 128)
	@ColumnPosition(7)
	private String nextTaskProcIds;

	@Column(name = "task_content", length = 512)
	@ColumnPosition(8)
	private String taskContent;

	@Column(name = "broker_id", length = 16)
	@ColumnPosition(9)
	private String brokerId;

	@Column(name = "broker_ip", length = 16)
	@ColumnPosition(10)
	private String brokerIp;

	@Column(name = "create_dt")
	@ColumnPosition(11)
	private Date createDt = new Date();

	@Column(name = "start_dt")
	@ColumnPosition(12)
	private Date startDt;

	@Column(name = "complete_dt")
	@ColumnPosition(13)
	private Date completeDt;

	@Column(name = "lastupd")
	@ColumnPosition(14)
	private Date lastupd = new Date();

	@Column(length = 64)
	@ColumnPosition(15)
	private String message;

	@Column(length = 4)
	@ColumnPosition(16)
	private String state = "1";

	public DataStashUnitTaskStateLogPo(String taskProcId, String unitProcId, String unitCode, String batchNo,
			String state) {
		this.taskProcId = taskProcId;
		this.unitProcId = unitProcId;
		this.unitCode = unitCode;
		this.batchNo = batchNo;
		this.state = state;
	}

	@Transient
	private String createDate;

	public String getCreateDate() {
		if (createDate == null || createDate.length() == 0) {
			createDate = DateHelper.formatDateTime(createDt);
		}
		return createDate;
	}

	public void setCreateDate(String createDate) {
		this.createDate = createDate;
		createDt = DateHelper.parseDateTime(createDate);
	}

	@Transient
	private String startDate;

	public String getStartDate() {
		if (startDate == null || startDate.length() == 0) {
			startDate = DateHelper.formatDateTime(startDt);
		}
		return "";
	}

	public void setStartDate(String startDate) {
		this.startDate = startDate;
		startDt = DateHelper.parseDateTime(startDate);
	}

	@Transient
	private String completeDate;

	public String getCompleteDate() {
		if (completeDate == null || completeDate.length() == 0) {
			completeDate = DateHelper.formatDateTime(completeDt);
		}
		return "";
	}

	public void setCompleteDate(String completeDate) {
		this.completeDate = completeDate;
		completeDt = DateHelper.parseDateTime(completeDate);
	}

	@Transient
	private String lastupDate;

	public String getLastupDate() {
		if (lastupDate == null || lastupDate.length() == 0) {
			lastupDate = DateHelper.formatDateTime(lastupd);
		}
		return createDate;
	}

	public void setLastupDate(String lastupDate) {
		this.lastupDate = lastupDate;
		lastupd = DateHelper.parseDateTime(lastupDate);
	}

}
